﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using log4net;

namespace RIMS.Lib.Utility
{
    public static class RIMSLogger
    {
        private static ILog Logger
        {
            get
            {
                return _Logger;
            }
        }

        private static readonly log4net.ILog _Logger = log4net.LogManager.GetLogger("RIMS.Lib");

        /// <summary>
        /// Log the exception in DAL and add a guid in exception
        /// </summary>
        /// <param name="ex"></param>
        public static void LogError(Exception ex)
        {
            //Log the error, give it a unique ID, re-throw so it can bubble up.
            string g = Guid.NewGuid().ToString();
            Logger.Error("Error GUID:" + g, ex);
            // ex.Data.Add("ErrorGUID", g); //Add this GUID to the exception so layers above can pull it out
        }

        /// <summary>
        /// Log the exception in DAL and add a guid in exception
        /// </summary>
        /// <param name="oid">OID of the object</param>
        /// <param name="ex"></param>
        public static void LogError(string oid, Exception ex)
        {
            //Log the error, give it a unique ID, re-throw so it can bubble up.
            string g = Guid.NewGuid().ToString();
            Logger.Error("Error GUID:" + g + " OID:" + oid, ex);
            ex.Data.Add("ErrorGUID", g); //Add this GUID to the exception so layers above can pull it out
        }

        /// <summary>
        /// Log the Infor in DAL and add a guid in exception
        /// </summary>
        /// <param name="info"> information you want to log</param>
        public static void LogInfo(string info)
        {
            Logger.Info(info);
        }
    }
}
